package chongchongchong.demo.service.impl;
import chongchongchong.demo.mapper.ParameterMapper;
import chongchongchong.demo.moudle.Parameter;
import chongchongchong.demo.service.ParameterService;
import chongchongchong.demo.view_object.DataVO;
import chongchongchong.demo.view_object.ParameterVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class ParameterServiceImpl  implements ParameterService {
    /**
     * 忽略error
     */
    @Autowired
    private ParameterMapper parameterMapper;

    @Override
    public DataVO<ParameterVO> findData() {
        DataVO dataVO = new DataVO();
        dataVO.setCode(0);
        dataVO.setMsg("");

        dataVO.setCount(parameterMapper.selectCount(null));
        List<Parameter> parameterList = parameterMapper.selectList(null);
        List<ParameterVO> parameterVOList = new ArrayList<>();
        for (Parameter parameter : parameterList) {
            ParameterVO parameterVO = new ParameterVO();
            BeanUtils.copyProperties(parameter,parameterVO);
            parameterVOList.add(parameterVO);
        }
        dataVO.setData(parameterVOList);

        return dataVO;
    }
}
